package com.stu.exercise.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.stu.exercise.entity.Customer;
import com.stu.exercise.entity.R;
import com.stu.exercise.mapper.CustomerMapper;
import com.stu.exercise.service.CustomerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper, Customer> implements CustomerService {

    @Autowired
    private CustomerMapper customerMapper;

    @Override
    public R getCustomerList() {
        List<Customer> customers = customerMapper.selectList(null);
        return R.success(customers);
    }

    @Override
    public R addCustomer(Customer customer) {
        int insert = customerMapper.insert(customer);
        if (insert < 1){
            return R.error(500, "添加失败");
        }
        return R.success("添加成功", null);
    }

    @Override
    public R editCustomer(Customer customer) {
        int i = customerMapper.updateById(customer);
        if (i < 1){
            return R.error(500, "修改失败");
        }
        return R.success("修改成功", null);
    }
}
